package org.jb.coinche.client.gui.card.impl;

import org.jb.coinche.client.gui.card.StatusPanel;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.util.Padding;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout.VBoxLayoutAlign;

/**
 * 
 * @author jeremie
 *
 */
public class StatusPanelImpl extends LayoutContainer implements StatusPanel {

	/*
	 * 
	 */
	public StatusPanelImpl() {
		VBoxLayout layout = new VBoxLayout();  
        layout.setPadding(new Padding(5));  
        layout.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);  
        setLayout(layout);  
	}
	

	/*
	 * (non-Javadoc)
	 * @see org.jb.coinche.client.gui.card.StatusPanel#setStatus(java.lang.String)
	 */
	@Override
	public void setStatus(String status) {
		removeAll();
		
		add( new Html( status ) );
		
		layout();		
	}

	/*
	 * (non-Javadoc)
	 * @see org.jb.coinche.client.gui.card.StatusPanel#setStatus(java.lang.String, java.lang.String, org.jb.coinche.client.gui.card.StatusPanel.ActionHandler)
	 */
	@Override
	public void setStatus(String status, String action, final ActionHandler handler) {
		
		removeAll();
		
		if (status != null)
			add( new Html( status ) );
		
		Button btn = new Button( action );
		btn.addSelectionListener( new SelectionListener<ButtonEvent>() {
			
			@Override
			public void componentSelected(ButtonEvent ce) {
				handler.execute();
			}
		});
		add( btn, new VBoxLayoutData( new Margins(5)) );
		
		layout();
		
	}

}
